using SS;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace SM.core
{
	internal class Bill
	{
		private Func objFunc = new Func();
		private string strConnection = "";
		public Bill()
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
		}
		public int action(string ID, DateTime CreateDate, float TotalMoney, string TypeInput, string WID, string Note, string PID, DataTable objTable, string TypeAct, string UserName, string FullName, float Discount, float MoneyAfterDiscount)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabBill", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("TotalMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("WID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Note", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("PID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("UserName", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("FullName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Discount", SqlDbType.Float);
				sqlCommand.Parameters.Add("MoneyAfterDiscount", SqlDbType.Float);
				sqlCommand.Parameters["ID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TotalMoney"].Value = TotalMoney;
				sqlCommand.Parameters["TypeInput"].Value = TypeInput;
				sqlCommand.Parameters["WID"].Value = WID;
				sqlCommand.Parameters["Note"].Value = Note;
				sqlCommand.Parameters["PID"].Value = PID;
				sqlCommand.Parameters["UserName"].Value = UserName;
				sqlCommand.Parameters["FullName"].Value = FullName;
				sqlCommand.Parameters["Discount"].Value = Discount;
				sqlCommand.Parameters["MoneyAfterDiscount"].Value = MoneyAfterDiscount;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				if (ID == "NEW")
				{
					ID = this.getNewBillID();
				}
				this.actionDetailBill(ID, CreateDate, objTable, TypeAct, WID);
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public int actionForward(string ID, DateTime CreateDate, float TotalMoney, string TypeInput, string WID, string Note, string PID, DataTable objTable, string TypeAct, string UserName, string FullName, float Discount, float MoneyAfterDiscount, string WidTarget)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabBill", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("TotalMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("WID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Note", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("PID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("UserName", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("FullName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Discount", SqlDbType.Float);
				sqlCommand.Parameters.Add("MoneyAfterDiscount", SqlDbType.Float);
				sqlCommand.Parameters["ID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TotalMoney"].Value = TotalMoney;
				sqlCommand.Parameters["TypeInput"].Value = TypeInput;
				sqlCommand.Parameters["WID"].Value = WID;
				sqlCommand.Parameters["Note"].Value = Note;
				sqlCommand.Parameters["PID"].Value = PID;
				sqlCommand.Parameters["UserName"].Value = UserName;
				sqlCommand.Parameters["FullName"].Value = FullName;
				sqlCommand.Parameters["Discount"].Value = Discount;
				sqlCommand.Parameters["MoneyAfterDiscount"].Value = MoneyAfterDiscount;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				if (ID == "NEW")
				{
					ID = this.getNewBillID();
				}
				this.actionDetailBillForward(ID, CreateDate, objTable, TypeAct, WID);
				SqlConnection sqlConnection2 = new SqlConnection(Program.strConnectionString);
				sqlConnection2.Open();
				SqlCommand sqlCommand2 = new SqlCommand("UPDATE [TabBill] SET [ActType] = 1 WHERE [ID] = '" + ID + "'", sqlConnection2);
				sqlCommand2.ExecuteNonQuery();
				sqlConnection2.Close();
				sqlConnection2.Dispose();
				string text = ID;
				ID = this.getBillIDForward(text);
				MessageBox.Show(ID);
				SqlConnection sqlConnection3 = new SqlConnection(Program.strConnectionString);
				sqlConnection3.Open();
				SqlCommand sqlCommand3 = new SqlCommand("ActionOnTabBillAsForward", sqlConnection3);
				sqlCommand3.CommandType = CommandType.StoredProcedure;
				sqlCommand3.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand3.Parameters.Add("TotalMoney", SqlDbType.Float);
				sqlCommand3.Parameters.Add("TypeInput", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters.Add("WID", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters.Add("Note", SqlDbType.NVarChar, 500);
				sqlCommand3.Parameters.Add("PID", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters.Add("UserName", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters.Add("FullName", SqlDbType.NVarChar, 250);
				sqlCommand3.Parameters.Add("Discount", SqlDbType.Float);
				sqlCommand3.Parameters.Add("MoneyAfterDiscount", SqlDbType.Float);
				sqlCommand3.Parameters.Add("forwardID", SqlDbType.VarChar, 50);
				sqlCommand3.Parameters["ID"].Value = ID;
				sqlCommand3.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand3.Parameters["TotalMoney"].Value = TotalMoney;
				sqlCommand3.Parameters["TypeInput"].Value = "IN1";
				sqlCommand3.Parameters["WID"].Value = WidTarget;
				sqlCommand3.Parameters["Note"].Value = Note;
				sqlCommand3.Parameters["PID"].Value = PID;
				sqlCommand3.Parameters["UserName"].Value = UserName;
				sqlCommand3.Parameters["FullName"].Value = FullName;
				sqlCommand3.Parameters["Discount"].Value = Discount;
				sqlCommand3.Parameters["MoneyAfterDiscount"].Value = MoneyAfterDiscount;
				sqlCommand3.Parameters["forwardID"].Value = text;
				sqlCommand3.ExecuteNonQuery();
				sqlConnection3.Close();
				sqlConnection3.Dispose();
				if (ID == "NEW")
				{
					ID = this.getNewBillID();
				}
				this.actionDetailBillAsInputForward(ID, CreateDate, objTable, "IN", WidTarget, text);
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public void setPriceInAverage(string PID)
		{
			double num = 0.0;
			int num2 = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("getListPriceInOfProduct", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("@Pid", SqlDbType.Int);
				sqlCommand.Parameters["@Pid"].Value = int.Parse(PID);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					num2++;
					num += double.Parse(sqlDataReader["ProductPrice"].ToString()) * double.Parse(sqlDataReader["Rate"].ToString());
				}
				sqlDataReader.Close();
				SqlCommand sqlCommand2 = new SqlCommand("UPDATE [TabProducts] SET [P_PriceBase] = " + Math.Round(num / (double)num2, 2).ToString() + " WHERE [PID] = " + PID, sqlConnection);
				sqlCommand2.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public void setPriceOutAverage(string PID)
		{
			double num = 0.0;
			int num2 = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("getListPriceOutOfProduct", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("@Pid", SqlDbType.Int);
				sqlCommand.Parameters["@Pid"].Value = int.Parse(PID);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					num2++;
					num += double.Parse(sqlDataReader["ProductPrice1"].ToString()) * double.Parse(sqlDataReader["Rate"].ToString());
				}
				sqlDataReader.Close();
				SqlCommand sqlCommand2 = new SqlCommand("UPDATE [TabProducts] SET [P_PriceTrade] = " + Math.Round(num / (double)num2, 2).ToString() + " WHERE [PID] = " + PID, sqlConnection);
				sqlCommand2.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public void setPriceOutRetailAverage(string PID)
		{
			double num = 0.0;
			int num2 = 0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("getListPriceOutRetailOfProduct", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("@Pid", SqlDbType.Int);
				sqlCommand.Parameters["@Pid"].Value = int.Parse(PID);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					num2++;
					num += double.Parse(sqlDataReader["ProductPrice2"].ToString()) * double.Parse(sqlDataReader["Rate"].ToString());
				}
				sqlDataReader.Close();
				SqlCommand sqlCommand2 = new SqlCommand("UPDATE [TabProducts] SET [P_PriceRetail] = " + Math.Round(num / (double)num2, 2).ToString() + " WHERE [PID] = " + PID, sqlConnection);
				sqlCommand2.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public int action(string ID, DateTime CreateDate, float TotalMoney, string TypeInput, string WID, string Note, string PID, DataTable objTable, string _Name, int _Age, int _Sex, string _Address, string _Phone, string TypeAct, string UserName, string FullName, string DoctorDesease, string CusID, float Discount, float MoneyAfterDiscount)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabBillRetail", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("TotalMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("WID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Note", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("PID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("_Name", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("_Age", SqlDbType.Int);
				sqlCommand.Parameters.Add("_Sex", SqlDbType.SmallInt);
				sqlCommand.Parameters.Add("_Address", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("_Phone", SqlDbType.NVarChar, 50);
				sqlCommand.Parameters.Add("UserName", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("FullName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("DoctorDesease", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("CusID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Discount", SqlDbType.Float);
				sqlCommand.Parameters.Add("MoneyAfterDiscount", SqlDbType.Float);
				sqlCommand.Parameters["ID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TotalMoney"].Value = TotalMoney;
				sqlCommand.Parameters["TypeInput"].Value = TypeInput;
				sqlCommand.Parameters["WID"].Value = WID;
				sqlCommand.Parameters["Note"].Value = Note;
				sqlCommand.Parameters["PID"].Value = PID;
				sqlCommand.Parameters["_Name"].Value = _Name;
				sqlCommand.Parameters["_Age"].Value = _Age;
				sqlCommand.Parameters["_Sex"].Value = _Sex;
				sqlCommand.Parameters["_Address"].Value = _Address;
				sqlCommand.Parameters["_Phone"].Value = _Phone;
				sqlCommand.Parameters["UserName"].Value = UserName;
				sqlCommand.Parameters["FullName"].Value = FullName;
				sqlCommand.Parameters["DoctorDesease"].Value = DoctorDesease;
				sqlCommand.Parameters["CusID"].Value = CusID;
				sqlCommand.Parameters["Discount"].Value = Discount;
				sqlCommand.Parameters["MoneyAfterDiscount"].Value = MoneyAfterDiscount;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				if (ID == "NEW")
				{
					ID = this.getNewBillID();
				}
				this.actionDetailBill(ID, CreateDate, objTable, TypeAct, WID);
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public int action(string ID, DateTime CreateDate, float TotalMoney, string TypeInput, string WID, string Note, string PID, DataTable objTable, string _Name, int _Age, int _Sex, string _Address, string _Phone, string TypeAct, string UserName, string FullName, string DoctorName, string DoctorAddress, string DoctorPhone, string DoctorDesease, string DoctorID, string CusID, float Discount, float MoneyAfterDiscount)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabBillRetailWithDoctor", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("TotalMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("WID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Note", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("PID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("_Name", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("_Age", SqlDbType.Int);
				sqlCommand.Parameters.Add("_Sex", SqlDbType.SmallInt);
				sqlCommand.Parameters.Add("_Address", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("_Phone", SqlDbType.NVarChar, 50);
				sqlCommand.Parameters.Add("UserName", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("FullName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("DoctorName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("DoctorAddress", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("DoctorPhone", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("DoctorDesease", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("_DoctorID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("CusID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Discount", SqlDbType.Float);
				sqlCommand.Parameters.Add("MoneyAfterDiscount", SqlDbType.Float);
				sqlCommand.Parameters["ID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TotalMoney"].Value = TotalMoney;
				sqlCommand.Parameters["TypeInput"].Value = TypeInput;
				sqlCommand.Parameters["WID"].Value = WID;
				sqlCommand.Parameters["Note"].Value = Note;
				sqlCommand.Parameters["PID"].Value = PID;
				sqlCommand.Parameters["_Name"].Value = _Name;
				sqlCommand.Parameters["_Age"].Value = _Age;
				sqlCommand.Parameters["_Sex"].Value = _Sex;
				sqlCommand.Parameters["_Address"].Value = _Address;
				sqlCommand.Parameters["_Phone"].Value = _Phone;
				sqlCommand.Parameters["UserName"].Value = UserName;
				sqlCommand.Parameters["FullName"].Value = FullName;
				sqlCommand.Parameters["DoctorName"].Value = DoctorName;
				sqlCommand.Parameters["DoctorAddress"].Value = DoctorAddress;
				sqlCommand.Parameters["DoctorPhone"].Value = DoctorPhone;
				sqlCommand.Parameters["DoctorDesease"].Value = DoctorDesease;
				sqlCommand.Parameters["_DoctorID"].Value = DoctorID;
				sqlCommand.Parameters["CusID"].Value = CusID;
				sqlCommand.Parameters["Discount"].Value = Discount;
				sqlCommand.Parameters["MoneyAfterDiscount"].Value = MoneyAfterDiscount;
				sqlCommand.ExecuteNonQuery();
				if (ID == "NEW")
				{
					ID = this.getNewBillID();
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.actionDetailBill(ID, CreateDate, objTable, TypeAct, WID);
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public string getNewBillID()
		{
			string result = "";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("getNewBillID", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters["ID"].Direction = ParameterDirection.Output;
				sqlCommand.Parameters["ID"].Value = "";
				sqlCommand.ExecuteNonQuery();
				result = sqlCommand.Parameters["ID"].Value.ToString();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public string getBillIDForward(string forwardID)
		{
			string result = "NEW";
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("getBillIDForward", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters["ID"].Direction = ParameterDirection.Output;
				sqlCommand.Parameters["ID"].Value = forwardID;
				sqlCommand.Parameters.Add("forwardID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters["forwardID"].Value = forwardID;
				sqlCommand.ExecuteNonQuery();
				result = sqlCommand.Parameters["ID"].Value.ToString();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public void actionDetailBill(string ID, DateTime CreateDate, DataTable objTable, string TypeAct, string StockID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabDetailBill", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("billID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Packet", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Pid", SqlDbType.Int);
				sqlCommand.Parameters.Add("productName", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("productUnit", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("productNumber", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("ProductExpiryDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("productPrice1", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice2", SqlDbType.Float);
				sqlCommand.Parameters.Add("NationalID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("VAT", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 4);
				sqlCommand.Parameters.Add("PossName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Rate", SqlDbType.Float);
				sqlCommand.Parameters.Add("IdRegisters", SqlDbType.VarChar, 100);
				sqlCommand.Parameters.Add("IdControl", SqlDbType.VarChar, 100);
				sqlCommand.Parameters.Add("IdBisMake", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("IdBisImport", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("StockID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("BarCode", SqlDbType.VarChar, 50);
				sqlCommand.Parameters["billID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TypeInput"].Value = TypeAct;
				for (int i = 0; i < objTable.Rows.Count; i++)
				{
					sqlCommand.Parameters["Packet"].Value = objTable.Rows[i]["Packet"].ToString();
					sqlCommand.Parameters["Pid"].Value = int.Parse(objTable.Rows[i]["Pid"].ToString());
					sqlCommand.Parameters["productName"].Value = objTable.Rows[i]["productName"].ToString();
					sqlCommand.Parameters["productUnit"].Value = objTable.Rows[i]["productUnit"].ToString();
					sqlCommand.Parameters["productNumber"].Value = float.Parse(objTable.Rows[i]["productNumber"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice"].Value = float.Parse(objTable.Rows[i]["productPrice"].ToString().Replace(",", ""));
					sqlCommand.Parameters["ProductMoney"].Value = float.Parse(objTable.Rows[i]["ProductMoney"].ToString());
					try
					{
						sqlCommand.Parameters["ProductDate"].Value = objTable.Rows[i]["ProductDate"].ToString();
					}
					catch
					{
					}
					try
					{
						sqlCommand.Parameters["ProductExpiryDate"].Value = objTable.Rows[i]["ProductExpiryDate"].ToString();
					}
					catch
					{
					}
					sqlCommand.Parameters["productPrice1"].Value = float.Parse(objTable.Rows[i]["productPrice1"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice2"].Value = float.Parse(objTable.Rows[i]["productPrice2"].ToString().Replace(",", ""));
					sqlCommand.Parameters["NationalID"].Value = objTable.Rows[i]["NationalID"].ToString();
					sqlCommand.Parameters["VAT"].Value = float.Parse(objTable.Rows[i]["VAT"].ToString());
					sqlCommand.Parameters["PossName"].Value = objTable.Rows[i]["possName"].ToString();
					sqlCommand.Parameters["Rate"].Value = float.Parse(objTable.Rows[i]["Rate"].ToString());
					sqlCommand.Parameters["IdRegisters"].Value = objTable.Rows[i]["IdRegisters"].ToString();
					sqlCommand.Parameters["IdControl"].Value = objTable.Rows[i]["IdControl"].ToString();
					sqlCommand.Parameters["IdBisMake"].Value = objTable.Rows[i]["IdBisMake"].ToString();
					sqlCommand.Parameters["IdBisImport"].Value = objTable.Rows[i]["IdBisImport"].ToString();
					sqlCommand.Parameters["StockID"].Value = StockID;
					sqlCommand.Parameters["BarCode"].Value = objTable.Rows[i]["BarCode"].ToString();
					sqlCommand.ExecuteNonQuery();
					if (TypeAct == "IN")
					{
						this.setPriceInAverage(objTable.Rows[i]["Pid"].ToString());
					}
					else
					{
						if (TypeAct == "OUT")
						{
							this.setPriceOutAverage(objTable.Rows[i]["Pid"].ToString());
						}
						else
						{
							if (TypeAct == "OUT4")
							{
								this.setPriceOutRetailAverage(objTable.Rows[i]["Pid"].ToString());
							}
						}
					}
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public void actionDetailBillAsInputForward(string ID, DateTime CreateDate, DataTable objTable, string TypeAct, string StockID, string forwardID)
		{
			try
			{
				for (int i = 0; i < objTable.Rows.Count; i++)
				{
					this.deleteBillDetailItem(objTable.Rows[i]["Pid"].ToString(), ID);
				}
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabDetailBillAsInputForward", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("billID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Packet", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Pid", SqlDbType.Int);
				sqlCommand.Parameters.Add("productName", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("productUnit", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("productNumber", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("ProductExpiryDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("productPrice1", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice2", SqlDbType.Float);
				sqlCommand.Parameters.Add("NationalID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("VAT", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 4);
				sqlCommand.Parameters.Add("PossName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Rate", SqlDbType.Float);
				sqlCommand.Parameters.Add("IdRegisters", SqlDbType.VarChar, 100);
				sqlCommand.Parameters.Add("IdControl", SqlDbType.VarChar, 100);
				sqlCommand.Parameters.Add("IdBisMake", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("IdBisImport", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("StockID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("forwardID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters["billID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TypeInput"].Value = TypeAct;
				for (int i = 0; i < objTable.Rows.Count; i++)
				{
					sqlCommand.Parameters["Packet"].Value = objTable.Rows[i]["Packet"].ToString();
					sqlCommand.Parameters["Pid"].Value = int.Parse(objTable.Rows[i]["Pid"].ToString());
					sqlCommand.Parameters["productName"].Value = objTable.Rows[i]["productName"].ToString();
					sqlCommand.Parameters["productUnit"].Value = objTable.Rows[i]["productUnit"].ToString();
					sqlCommand.Parameters["productNumber"].Value = float.Parse(objTable.Rows[i]["productNumber"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice"].Value = float.Parse(objTable.Rows[i]["productPrice"].ToString().Replace(",", ""));
					sqlCommand.Parameters["ProductMoney"].Value = float.Parse(objTable.Rows[i]["ProductMoney"].ToString());
					try
					{
						sqlCommand.Parameters["ProductDate"].Value = objTable.Rows[i]["ProductDate"].ToString();
					}
					catch
					{
					}
					try
					{
						sqlCommand.Parameters["ProductExpiryDate"].Value = objTable.Rows[i]["ProductExpiryDate"].ToString();
					}
					catch
					{
					}
					sqlCommand.Parameters["productPrice1"].Value = float.Parse(objTable.Rows[i]["productPrice1"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice2"].Value = float.Parse(objTable.Rows[i]["productPrice2"].ToString().Replace(",", ""));
					sqlCommand.Parameters["NationalID"].Value = objTable.Rows[i]["NationalID"].ToString();
					sqlCommand.Parameters["VAT"].Value = float.Parse(objTable.Rows[i]["VAT"].ToString());
					sqlCommand.Parameters["PossName"].Value = objTable.Rows[i]["possName"].ToString();
					sqlCommand.Parameters["Rate"].Value = float.Parse(objTable.Rows[i]["Rate"].ToString());
					sqlCommand.Parameters["IdRegisters"].Value = objTable.Rows[i]["IdRegisters"].ToString();
					sqlCommand.Parameters["IdControl"].Value = objTable.Rows[i]["IdControl"].ToString();
					sqlCommand.Parameters["IdBisMake"].Value = objTable.Rows[i]["IdBisMake"].ToString();
					sqlCommand.Parameters["IdBisImport"].Value = objTable.Rows[i]["IdBisImport"].ToString();
					sqlCommand.Parameters["StockID"].Value = StockID;
					sqlCommand.Parameters["forwardID"].Value = forwardID;
					sqlCommand.ExecuteNonQuery();
					if (TypeAct == "IN")
					{
						this.setPriceInAverage(objTable.Rows[i]["Pid"].ToString());
					}
					else
					{
						if (TypeAct == "OUT")
						{
							this.setPriceOutAverage(objTable.Rows[i]["Pid"].ToString());
						}
						else
						{
							if (TypeAct == "OUT4")
							{
								this.setPriceOutRetailAverage(objTable.Rows[i]["Pid"].ToString());
							}
						}
					}
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public void actionDetailBillForward(string ID, DateTime CreateDate, DataTable objTable, string TypeAct, string StockID)
		{
			try
			{
				for (int i = 0; i < objTable.Rows.Count; i++)
				{
					this.deleteBillDetailItem(objTable.Rows[i]["Pid"].ToString(), ID);
				}
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabDetailBillForward", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("billID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Packet", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Pid", SqlDbType.Int);
				sqlCommand.Parameters.Add("productName", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("productUnit", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("productNumber", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("ProductExpiryDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("CreateDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("productPrice1", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice2", SqlDbType.Float);
				sqlCommand.Parameters.Add("NationalID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("VAT", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 4);
				sqlCommand.Parameters.Add("PossName", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("Rate", SqlDbType.Float);
				sqlCommand.Parameters["billID"].Value = ID;
				sqlCommand.Parameters["CreateDate"].Value = CreateDate;
				sqlCommand.Parameters["TypeInput"].Value = TypeAct;
				for (int i = 0; i < objTable.Rows.Count; i++)
				{
					sqlCommand.Parameters["Packet"].Value = objTable.Rows[i]["Packet"].ToString();
					sqlCommand.Parameters["Pid"].Value = int.Parse(objTable.Rows[i]["Pid"].ToString());
					sqlCommand.Parameters["productName"].Value = objTable.Rows[i]["productName"].ToString();
					sqlCommand.Parameters["productUnit"].Value = objTable.Rows[i]["productUnit"].ToString();
					sqlCommand.Parameters["productNumber"].Value = float.Parse(objTable.Rows[i]["productNumber"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice"].Value = float.Parse(objTable.Rows[i]["productPrice"].ToString().Replace(",", ""));
					sqlCommand.Parameters["ProductMoney"].Value = float.Parse(objTable.Rows[i]["ProductMoney"].ToString());
					try
					{
						sqlCommand.Parameters["ProductDate"].Value = objTable.Rows[i]["ProductDate"].ToString();
					}
					catch
					{
					}
					try
					{
						sqlCommand.Parameters["ProductExpiryDate"].Value = objTable.Rows[i]["ProductExpiryDate"].ToString();
					}
					catch
					{
					}
					sqlCommand.Parameters["productPrice1"].Value = float.Parse(objTable.Rows[i]["productPrice1"].ToString().Replace(",", ""));
					sqlCommand.Parameters["productPrice2"].Value = float.Parse(objTable.Rows[i]["productPrice2"].ToString().Replace(",", ""));
					sqlCommand.Parameters["NationalID"].Value = objTable.Rows[i]["NationalID"].ToString();
					sqlCommand.Parameters["VAT"].Value = float.Parse(objTable.Rows[i]["VAT"].ToString());
					sqlCommand.Parameters["PossName"].Value = objTable.Rows[i]["possName"].ToString();
					sqlCommand.Parameters["Rate"].Value = float.Parse(objTable.Rows[i]["Rate"].ToString());
					sqlCommand.ExecuteNonQuery();
					if (TypeAct == "IN")
					{
						this.setPriceInAverage(objTable.Rows[i]["Pid"].ToString());
					}
					else
					{
						if (TypeAct == "OUT")
						{
							this.setPriceOutAverage(objTable.Rows[i]["Pid"].ToString());
						}
						else
						{
							if (TypeAct == "OUT4")
							{
								this.setPriceOutRetailAverage(objTable.Rows[i]["Pid"].ToString());
							}
						}
					}
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public DataTable getDetailBillVAT(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Pid", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductUnit", typeof(string));
				DataColumn column4 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column5 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column6 = new DataColumn("ProductMoney", typeof(string));
				DataColumn column7 = new DataColumn("Packet", typeof(string));
				DataColumn column8 = new DataColumn("ProductDate", typeof(DateTime));
				DataColumn column9 = new DataColumn("ProductExpiryDate", typeof(DateTime));
				DataColumn column10 = new DataColumn("ProductPrice1", typeof(string));
				DataColumn column11 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column12 = new DataColumn("NationalID", typeof(string));
				DataColumn column13 = new DataColumn("VATasMoney", typeof(float));
				DataColumn column14 = new DataColumn("possName", typeof(string));
				DataColumn column15 = new DataColumn("Rate", typeof(string));
				DataColumn column16 = new DataColumn("IdRegisters", typeof(string));
				DataColumn column17 = new DataColumn("IdControl", typeof(string));
				DataColumn column18 = new DataColumn("IdBisMake", typeof(string));
				DataColumn column19 = new DataColumn("IdBisImport", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				dataTable.Columns.Add(column6);
				dataTable.Columns.Add(column7);
				dataTable.Columns.Add(column8);
				dataTable.Columns.Add(column9);
				dataTable.Columns.Add(column10);
				dataTable.Columns.Add(column11);
				dataTable.Columns.Add(column12);
				dataTable.Columns.Add(column13);
				dataTable.Columns.Add(column14);
				dataTable.Columns.Add(column15);
				dataTable.Columns.Add(column16);
				dataTable.Columns.Add(column17);
				dataTable.Columns.Add(column18);
				dataTable.Columns.Add(column19);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT * FROM [TabDetailBill] WHERE [billID] IN (" + ID + ")";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Pid"].ToString(),
						sqlDataReader["ProductName"].ToString(),
						sqlDataReader["ProductUnit"].ToString(),
						string.Format("{0:0,0}", double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString())),
						sqlDataReader["Packet"].ToString(),
						sqlDataReader["ProductDate"].ToString(),
						sqlDataReader["ProductExpiryDate"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice1"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice2"].ToString())),
						sqlDataReader["NationalID"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["VATasMoney"].ToString())),
						sqlDataReader["PossName"],
						sqlDataReader["Rate"].ToString(),
						sqlDataReader["IdRegisters"].ToString(),
						sqlDataReader["IdControl"].ToString(),
						sqlDataReader["IdBisMake"].ToString(),
						sqlDataReader["IdBisImport"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBill(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Pid", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductUnit", typeof(string));
				DataColumn column4 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column5 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column6 = new DataColumn("ProductMoney", typeof(string));
				DataColumn column7 = new DataColumn("Packet", typeof(string));
				DataColumn column8 = new DataColumn("ProductDate", typeof(DateTime));
				DataColumn column9 = new DataColumn("ProductExpiryDate", typeof(DateTime));
				DataColumn column10 = new DataColumn("ProductPrice1", typeof(string));
				DataColumn column11 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column12 = new DataColumn("NationalID", typeof(string));
				DataColumn column13 = new DataColumn("VAT", typeof(string));
				DataColumn column14 = new DataColumn("possName", typeof(string));
				DataColumn column15 = new DataColumn("Rate", typeof(string));
				DataColumn column16 = new DataColumn("IdRegisters", typeof(string));
				DataColumn column17 = new DataColumn("IdControl", typeof(string));
				DataColumn column18 = new DataColumn("IdBisMake", typeof(string));
				DataColumn column19 = new DataColumn("IdBisImport", typeof(string));
				DataColumn column20 = new DataColumn("VATasMoney", typeof(float));
				DataColumn column21 = new DataColumn("Barcode", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				dataTable.Columns.Add(column6);
				dataTable.Columns.Add(column7);
				dataTable.Columns.Add(column8);
				dataTable.Columns.Add(column9);
				dataTable.Columns.Add(column10);
				dataTable.Columns.Add(column11);
				dataTable.Columns.Add(column12);
				dataTable.Columns.Add(column13);
				dataTable.Columns.Add(column14);
				dataTable.Columns.Add(column15);
				dataTable.Columns.Add(column16);
				dataTable.Columns.Add(column17);
				dataTable.Columns.Add(column18);
				dataTable.Columns.Add(column19);
				dataTable.Columns.Add(column20);
				dataTable.Columns.Add(column21);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT Pid, ProductName, ProductUnit, Packet, ISNULL(ProductNumber,0) AS ProductNumber, ISNULL(ProductMoney,0) AS ProductMoney, ISNULL(ProductPrice,0) AS ProductPrice, ISNULL(ProductPrice1,0) AS ProductPrice1, ISNULL(ProductPrice2,0) AS ProductPrice2, ISNULL(VAT,0) AS VAT, ISNULL(Rate,0) AS Rate, ISNULL(VATasMoney,0) AS VATasMoney, ProductDate, ProductExpiryDate, NationalID, VAT, PossName, Rate,IdRegisters, IdControl, IdBisMake, IdBisImport, BarCode FROM [TabDetailBill] WHERE [billID] = '" + ID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Pid"].ToString(),
						sqlDataReader["ProductName"].ToString(),
						sqlDataReader["ProductUnit"].ToString(),
						string.Format("{0:0,0}", double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString())),
						sqlDataReader["Packet"].ToString(),
						sqlDataReader["ProductDate"].ToString(),
						sqlDataReader["ProductExpiryDate"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice1"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice2"].ToString())),
						sqlDataReader["NationalID"].ToString(),
						sqlDataReader["VAT"].ToString(),
						sqlDataReader["PossName"],
						sqlDataReader["Rate"].ToString(),
						sqlDataReader["IdRegisters"].ToString(),
						sqlDataReader["IdControl"].ToString(),
						sqlDataReader["IdBisMake"].ToString(),
						sqlDataReader["IdBisImport"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["VATasMoney"].ToString())),
						sqlDataReader["BarCode"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillCusFree(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("CreateDate", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column4 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column5 = new DataColumn("ProductMoney", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [ProductName],[ProductNumber], [ProductPrice2], [ProductMoney], [TabBill].[CreateDate] FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND [TabDetailBill].[billID] IN ( SELECT [ID] FROM  [TabBill] WHERE [_CusFreeID] = '" + ID + "')  ORDER BY [CreateDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					string text;
					if (this.checkInObjTable(sqlDataReader["CreateDate"].ToString(), dataTable))
					{
						text = "";
					}
					else
					{
						text = sqlDataReader["CreateDate"].ToString().Substring(0, 10);
					}
					dataTable.Rows.Add(new object[]
					{
						text,
						sqlDataReader["ProductName"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice2"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString()))
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillCusSale(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("CreateDate", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column4 = new DataColumn("ProductPrice1", typeof(string));
				DataColumn column5 = new DataColumn("ProductMoney", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [ProductName],[ProductNumber], [ProductPrice1], [ProductMoney], [TabBill].[CreateDate] FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND [TabDetailBill].[billID] IN ( SELECT [ID] FROM  [TabBill] WHERE [PID] = '" + ID + "')  ORDER BY [CreateDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					string text;
					if (this.checkInObjTable(sqlDataReader["CreateDate"].ToString(), dataTable))
					{
						text = "";
					}
					else
					{
						text = sqlDataReader["CreateDate"].ToString().Substring(0, 10);
					}
					dataTable.Rows.Add(new object[]
					{
						text,
						sqlDataReader["ProductName"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice1"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString()))
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillByProvider(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("CreateDate", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column4 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column5 = new DataColumn("ProductMoney", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [ProductName],[ProductNumber], [ProductPrice], [ProductMoney], [TabBill].[CreateDate] FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND [TabDetailBill].[billID] IN ( SELECT [ID] FROM  [TabBill] WHERE [PID] = '" + ID + "')  ORDER BY [CreateDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					string text;
					if (this.checkInObjTable(sqlDataReader["CreateDate"].ToString(), dataTable))
					{
						text = "";
					}
					else
					{
						text = sqlDataReader["CreateDate"].ToString().Substring(0, 10);
					}
					dataTable.Rows.Add(new object[]
					{
						text,
						sqlDataReader["ProductName"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString()))
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillByDoctor(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("CreateDate", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column4 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column5 = new DataColumn("ProductMoney", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [ProductName],[ProductNumber], [ProductPrice2], [ProductMoney], [TabBill].[CreateDate] FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND [TabDetailBill].[billID] IN ( SELECT [ID] FROM  [TabBill] WHERE [_DoctorID] = '" + ID + "')  ORDER BY [CreateDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					string text;
					if (this.checkInObjTable(sqlDataReader["CreateDate"].ToString(), dataTable))
					{
						text = "";
					}
					else
					{
						text = sqlDataReader["CreateDate"].ToString().Substring(0, 10);
					}
					dataTable.Rows.Add(new object[]
					{
						text,
						sqlDataReader["ProductName"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice2"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString()))
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillInput(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("CreateDate", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column4 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column5 = new DataColumn("ProductMoney", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [ProductName],[ProductNumber], [ProductPrice], [ProductMoney], [TabBill].[CreateDate] FROM [TabDetailBill],[TabBill] WHERE [TabDetailBill].[billID] = [TabBill].[ID] AND [TabDetailBill].[billID] IN ( SELECT [ID] FROM  [TabBill] WHERE [PID] = '" + ID + "')  ORDER BY [CreateDate]";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					string text;
					if (this.checkInObjTable(sqlDataReader["CreateDate"].ToString(), dataTable))
					{
						text = "";
					}
					else
					{
						text = sqlDataReader["CreateDate"].ToString().Substring(0, 10);
					}
					dataTable.Rows.Add(new object[]
					{
						text,
						sqlDataReader["ProductName"].ToString(),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductNumber"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductPrice"].ToString())),
						string.Format(Program.lenAffterDecimal, double.Parse(sqlDataReader["ProductMoney"].ToString()))
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		private bool checkInObjTable(string tmpDate, DataTable tmpTbale)
		{
			bool flag = false;
			bool result;
			for (int i = 0; i < tmpTbale.Rows.Count; i++)
			{
				if (tmpTbale.Rows[i]["CreateDate"].ToString() == tmpDate.Substring(0, 10))
				{
					flag = true;
					result = flag;
					return result;
				}
			}
			result = flag;
			return result;
		}
		public DataTable getDetailBillDeleted(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Pid", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductUnit", typeof(string));
				DataColumn column4 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column5 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column6 = new DataColumn("ProductMoney", typeof(string));
				DataColumn column7 = new DataColumn("Packet", typeof(string));
				DataColumn column8 = new DataColumn("ProductDate", typeof(DateTime));
				DataColumn column9 = new DataColumn("ProductExpiryDate", typeof(DateTime));
				DataColumn column10 = new DataColumn("ProductPrice1", typeof(string));
				DataColumn column11 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column12 = new DataColumn("NationalID", typeof(string));
				DataColumn column13 = new DataColumn("VAT", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				dataTable.Columns.Add(column6);
				dataTable.Columns.Add(column7);
				dataTable.Columns.Add(column8);
				dataTable.Columns.Add(column9);
				dataTable.Columns.Add(column10);
				dataTable.Columns.Add(column11);
				dataTable.Columns.Add(column12);
				dataTable.Columns.Add(column13);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT * FROM [TabDetailBillDeleted] WHERE [billID] = '" + ID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Pid"].ToString(),
						sqlDataReader["ProductName"].ToString(),
						sqlDataReader["ProductUnit"].ToString(),
						sqlDataReader["ProductNumber"].ToString(),
						sqlDataReader["ProductPrice"].ToString(),
						sqlDataReader["ProductMoney"].ToString(),
						sqlDataReader["Packet"].ToString(),
						sqlDataReader["ProductDate"].ToString(),
						sqlDataReader["ProductExpiryDate"].ToString(),
						sqlDataReader["ProductPrice1"].ToString(),
						sqlDataReader["ProductPrice2"].ToString(),
						sqlDataReader["NationalID"].ToString(),
						sqlDataReader["VAT"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				result = null;
			}
			return result;
		}
		public DataTable getDetailBillSurplus(string ID)
		{
			DataTable result;
			try
			{
				DataTable dataTable = new DataTable();
				DataColumn column = new DataColumn("Pid", typeof(string));
				DataColumn column2 = new DataColumn("ProductName", typeof(string));
				DataColumn column3 = new DataColumn("ProductUnit", typeof(string));
				DataColumn column4 = new DataColumn("ProductNumber", typeof(string));
				DataColumn column5 = new DataColumn("ProductPrice", typeof(string));
				DataColumn column6 = new DataColumn("ProductMoney", typeof(string));
				DataColumn column7 = new DataColumn("Packet", typeof(string));
				DataColumn column8 = new DataColumn("ProductDate", typeof(DateTime));
				DataColumn column9 = new DataColumn("ProductExpiryDate", typeof(DateTime));
				DataColumn column10 = new DataColumn("ProductPrice1", typeof(string));
				DataColumn column11 = new DataColumn("ProductPrice2", typeof(string));
				DataColumn column12 = new DataColumn("NationalID", typeof(string));
				DataColumn column13 = new DataColumn("VAT", typeof(string));
				DataColumn column14 = new DataColumn("Surplus", typeof(string));
				dataTable.Columns.Add(column);
				dataTable.Columns.Add(column2);
				dataTable.Columns.Add(column3);
				dataTable.Columns.Add(column4);
				dataTable.Columns.Add(column5);
				dataTable.Columns.Add(column6);
				dataTable.Columns.Add(column7);
				dataTable.Columns.Add(column8);
				dataTable.Columns.Add(column9);
				dataTable.Columns.Add(column10);
				dataTable.Columns.Add(column11);
				dataTable.Columns.Add(column12);
				dataTable.Columns.Add(column13);
				dataTable.Columns.Add(column14);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT * FROM [TabDetailBill] WHERE [billID] = '" + ID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					dataTable.Rows.Add(new object[]
					{
						sqlDataReader["Pid"].ToString(),
						sqlDataReader["ProductName"].ToString(),
						sqlDataReader["ProductUnit"].ToString(),
						sqlDataReader["ProductNumber"].ToString(),
						sqlDataReader["ProductPrice"].ToString(),
						sqlDataReader["ProductMoney"].ToString(),
						sqlDataReader["Packet"].ToString(),
						sqlDataReader["ProductDate"].ToString(),
						sqlDataReader["ProductExpiryDate"].ToString(),
						sqlDataReader["ProductPrice1"].ToString(),
						sqlDataReader["ProductPrice2"].ToString(),
						sqlDataReader["NationalID"].ToString(),
						sqlDataReader["VAT"].ToString(),
						sqlDataReader["Surplus"].ToString()
					});
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = dataTable;
			}
			catch
			{
				result = null;
			}
			return result;
		}
		public int delItem(string ID)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT billID, Pid FROM TabDetailBill WHERE [billID] = '" + ID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					this.delProductItem(ID, sqlDataReader["Pid"].ToString());
				}
				sqlDataReader.Close();
				sqlCommand.CommandText = "DELETE FROM TabBill WHERE ID = '" + ID + "'";
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				result = 1;
			}
			return result;
		}
		public void delProductItem(string billID, string productID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "DELETE TabDetailBill WHERE [billID] = '" + billID + "' AND [Pid] = " + productID;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public void setPrinted(string ID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("UPDATE [TabBill] SET [Printed] = 1 WHERE [ID] = '" + ID + "'", sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public bool getPrinted(string ID)
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("SELECT [Printed] FROM [TabBill] WHERE [ID] = '" + ID + "'", sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					result = (sqlDataReader["Printed"].ToString() == "True");
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
		public bool checkID(string ID)
		{
			bool result = false;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				string cmdText = "SELECT * FROM [TabBill] WHERE [ID] = '" + ID + "'";
				SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				if (sqlDataReader.HasRows)
				{
					result = true;
				}
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = false;
			}
			return result;
		}
		public string getRetailID()
		{
			string text = this.objFunc.GetPerfixOutRetail();
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 * FROM [TabBill] WHERE [TypeInput] = 'OUT4' ORDER BY [CreateDate] DESC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["ID"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = text;
				return result;
			}
			result = text;
			return result;
		}
		public string getNewestRetailID()
		{
			string text = "";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 * FROM [TabBill] WHERE [TypeInput] = 'OUT4' ORDER BY [AutoItem] DESC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["ID"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = text;
				return result;
			}
			result = text;
			return result;
		}
		public string getBillDoctor(string billID)
		{
			string text = "";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 ID FROM [TabPrescription] WHERE [billID] = '" + billID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["ID"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = text;
				return result;
			}
			result = text;
			return result;
		}
		public void deleteBillDetailItem(string Pid, string billID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = string.Concat(new string[]
				{
					"DELETE TabDetailBill WHERE [Pid] = ",
					Pid,
					" AND BillID = '",
					billID,
					"'"
				});
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		public string getInBillID()
		{
			string text = this.objFunc.GetPerfixIn();
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 * FROM [TabBill] WHERE [TypeInput] IN('IN1','IN2','IN3') ORDER BY [CreateDate] DESC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["ID"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = text;
				return result;
			}
			result = text;
			return result;
		}
		public string getuserNameBillID(string ID)
		{
			string text = "-";
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT [userName] FROM [TabBill] WHERE [ID] = '" + ID + "'";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["userName"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = "-";
				return result;
			}
			result = text;
			return result;
		}
		public string getOutBillID()
		{
			string text = this.objFunc.GetPerfixOut();
			string result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 1 * FROM [TabBill] WHERE [TypeInput] IN('OUT1','OUT3') ORDER BY [CreateDate] DESC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					text = sqlDataReader["ID"].ToString();
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				result = text;
				return result;
			}
			result = text;
			return result;
		}
		public void AllUpdateBalancerDeleted(string Packet, string Pid, string StockID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = string.Concat(new string[]
				{
					"DELETE FROM [TabTotalBalancer] WHERE [Packet] = '",
					Packet,
					"' AND [Pid] = ",
					Pid,
					" AND StockID = '",
					StockID,
					"'"
				});
				sqlCommand.ExecuteNonQuery();
				SqlCommand sqlCommand2 = sqlConnection.CreateCommand();
				sqlCommand2.CommandText = string.Concat(new string[]
				{
					"SELECT [TabBill].[WID],[TabBill].[TypeInput],[TabDetailBill].[Packet],[TabDetailBill].[Pid],[TabDetailBill].[productName],[productUnit],[productNumber],[productPrice],[ProductDate],[ProductExpiryDate],[NationalID],[VAT],[Rate] FROM [TabDetailBill],[TabBill] WHERE [TabBill].[ID] = [TabDetailBill].[billID] AND [TabDetailBill].[Pid] = ",
					Pid,
					" AND [Packet] = '",
					Packet,
					"' AND [TabBill].[WID] = '",
					StockID,
					"'"
				});
				SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader();
				while (sqlDataReader.Read())
				{
					this.updateBalancer(sqlDataReader["Packet"].ToString(), int.Parse(sqlDataReader["Pid"].ToString()), sqlDataReader["productName"].ToString(), sqlDataReader["productUnit"].ToString(), int.Parse(sqlDataReader["productNumber"].ToString()), float.Parse(sqlDataReader["productPrice"].ToString()), (float)int.Parse(sqlDataReader["productNumber"].ToString()) * float.Parse(sqlDataReader["productPrice"].ToString()), sqlDataReader["ProductDate"].ToString(), sqlDataReader["ProductExpiryDate"].ToString(), sqlDataReader["NationalID"].ToString(), float.Parse(sqlDataReader["VAT"].ToString()), sqlDataReader["TypeInput"].ToString(), float.Parse(sqlDataReader["Rate"].ToString()), StockID);
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show("Error : \r\n" + ex.Message);
			}
		}
		private void updateBalancer(string Packet, int Pid, string productName, string productUnit, int productNumber, float productPrice, float ProductMoney, string ProductDate, string ProductExpiryDate, string NationalID, float VAT, string TypeInput, float Rate, string StockID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionUpdateBalancer", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("Packet", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("Pid", SqlDbType.Int);
				sqlCommand.Parameters.Add("productName", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("productUnit", SqlDbType.NVarChar, 250);
				sqlCommand.Parameters.Add("productNumber", SqlDbType.Float);
				sqlCommand.Parameters.Add("productPrice", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductMoney", SqlDbType.Float);
				sqlCommand.Parameters.Add("ProductDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("ProductExpiryDate", SqlDbType.DateTime);
				sqlCommand.Parameters.Add("NationalID", SqlDbType.VarChar, 50);
				sqlCommand.Parameters.Add("VAT", SqlDbType.Float);
				sqlCommand.Parameters.Add("TypeInput", SqlDbType.VarChar, 4);
				sqlCommand.Parameters.Add("Rate", SqlDbType.Float);
				sqlCommand.Parameters.Add("StockID", SqlDbType.VarChar);
				sqlCommand.Parameters["TypeInput"].Value = TypeInput;
				sqlCommand.Parameters["Packet"].Value = Packet;
				sqlCommand.Parameters["Pid"].Value = Pid;
				sqlCommand.Parameters["productName"].Value = productName;
				sqlCommand.Parameters["productUnit"].Value = productUnit;
				sqlCommand.Parameters["productNumber"].Value = productNumber;
				sqlCommand.Parameters["productPrice"].Value = productPrice;
				sqlCommand.Parameters["ProductMoney"].Value = ProductMoney;
				try
				{
					sqlCommand.Parameters["ProductDate"].Value = ProductDate;
				}
				catch
				{
				}
				try
				{
					sqlCommand.Parameters["ProductExpiryDate"].Value = ProductExpiryDate;
				}
				catch
				{
				}
				sqlCommand.Parameters["NationalID"].Value = NationalID;
				sqlCommand.Parameters["VAT"].Value = VAT;
				sqlCommand.Parameters["Rate"].Value = Rate;
				sqlCommand.Parameters["StockID"].Value = StockID;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		public double getVATofProduct(string Packet, string Pid)
		{
			double result = 0.0;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = string.Concat(new string[]
				{
					"SELECT VAT FROM TabDetailBill WHERE Packet = '",
					Packet,
					"' AND Pid = ",
					Pid,
					" AND billID IN (SELECT ID FROM TabBill WHERE TypeInput = 'IN1')"
				});
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					try
					{
						result = double.Parse(sqlDataReader["VAT"].ToString());
					}
					catch
					{
						result = 0.0;
					}
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
			return result;
		}
	}
}
